import Reqwest from '../../utils/Reqwest';
import {MediaTypeBean} from './MediaTypeBean';
import {base, assign, redirect}  from '../base/Base';
import {ResponseDto} from '../base/BaseDTO';
declare let GLOBAL: any;

export class MediaTypeController {
    path = `${GLOBAL.baseApiUrl}/adMediaType/api`;


    /**
     * searchMediaType
     * 查询MediaType列表
     * @param {*} [params] 
     * @param {any} [options={}] 
     * @returns {Promise<any>} 
     * 
     * @memberOf MediaTypeController
     */
    searchMediaType(params?:any,
        options = {}): Promise<any> {
        return new Reqwest(assign({
            url: `${this.path}/list.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: params || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    /**
     * getMediaType
     * 根据ID查询MediaType信息
     * @param {{
     *         id:number
     *     }} params 
     * @param {any} [options={}] 
     * @returns {Promise<ResponseDto<MediaTypeBean<any>>>} 
     * 
     * @memberOf MediaTypeController
     */
    getMediaType(params: {
        id:number
    }, options = {}): Promise<ResponseDto<MediaTypeBean<any>>> {
        return new Reqwest(assign({
            url: `${this.path}/getView.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: params || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    /**
     * editMediaType
     * 编辑MediaType
     * @param {MediaTypeBean<any>} params 
     * @param {any} [options={}] 
     * @returns {Promise<ResponseDto<any>>} 
     * 
     * @memberOf MediaTypeController
     */
    editMediaType(params: MediaTypeBean<any>, options = {}): Promise<ResponseDto<any>> {
        return new Reqwest(assign({
            url: `${this.path}/update.jhtml`,
            method: 'post',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(params) || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    /**
     * addMediaType
     * 新增MediaType
     * @param {MediaTypeBean<any>} params 
     * @param {any} [options={}] 
     * @returns {Promise<ResponseDto<any>>} 
     * 
     * @memberOf MediaTypeController
     */
    addMediaType(params: MediaTypeBean<any>, options = {}): Promise<ResponseDto<any>> {
        return new Reqwest(assign({
            url: `${this.path}/create.jhtml`,
            method: 'post',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(params) || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    /**
     * deleteMediaType
     * 删除MediaType
     * @param {{
     *         id:number
     *     }} params 
     * @param {any} [options={}] 
     * @returns {Promise<ResponseDto<any>>} 
     * 
     * @memberOf MediaTypeController
     */
    deleteMediaType(params: {
        id:number
    }, options = {}): Promise<ResponseDto<any>> {
        return new Reqwest(assign({
            url: `${this.path}/delete.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: params || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }
}